package com.demo.di.event;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 描述：
 *
 * @author lida
 * @time 2019/10/15 15:25
 */
public class Publisher implements ApplicationContextAware {
	private ApplicationContext ctx;
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		this.ctx = applicationContext;
	}

	public void publish(String message){
		ctx.publishEvent(new MessageEvent(this, message));
	}

	public static void main(String[] args) {
		ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:/com/demo/di/event/publisher.xml");
		Publisher publisher = ctx.getBean("publisher", Publisher.class);
		publisher.publish("I wish that my baby yun can become a happy girl");
		publisher.publish("...Message in a bottle");
	}
}
